'''
Created on 2020年3月4日

@author: yinfs
'''
from dao import dbaccess
from dao import pcsdao
from bo import fileutil
from bo import checksystem
from conf import config
from bo import pcsbo
import time

def testSqlite():
    db = dbaccess.DBAccess()
#     print("创建数据库表")
#     sql1='''
#     create table stu(
#         id integer primary key autoincrement,
#         name text,      
#         age integer)
#     '''
#     C1 = db.executeCreate(sql1)
#     if C1:
#         print('创建成功！')
#     else:
#         print('创建失败！')
        
#     print("插入Student信息")
#     ob = [("张三",20),("李四",30)]
#     sql = 'insert into stu (name, age) values (?,?)'
#     T = db.executeUpdate(sql, ob)
#     if T:
#         print('插入成功！')
#     else:
#         print('插入失败！')
    
    print("通姓名查询Student信息")
    sql = 'select * from stu where name=?'
    ob = ['yinfs']
    s = db.executeQuery(sql, ob)
    st = []
    for st in s:
        print('ID:', st[0], '  Name:', st[1], '  Age:', st[2])
    if any(st):
        pass
    else:
        print("输入有误，该学员不存在")
    db.close()
         
def test2():
    try:
        filePath = 'D:/test/11'
        conf = config.Config()
        extensionTypeList = conf.get_config_values('ExtensionType','type').split(',')
        fu = fileutil.FileUtil()
        photoList = fu.get_photo_info_list(filePath, extensionTypeList)
        print(photoList)
    except Exception as e:
        print('错误类型： ', e)

def start_app():
    db = dbaccess.DBAccess()
    try:
        check = checksystem.CheckSystem()
        ckr=check.check_system()
        print("环境检查：",ckr)
        if ckr:
            #检查环境成功
            filePath = 'E:/家庭照片'
            conf = config.Config()
            extensionTypeList = conf.get_config_values('ExtensionType','type').split(',')
            fu = fileutil.FileUtil()
            photoList = fu.get_photo_info_list_partition(filePath, extensionTypeList)
#             print("photoList="+photoList)
#             sql = 'insert into photo_class (source_name,file_md5,new_filename,image_datetime,image_mark,image_model,image_length,image_width) values (?,?,?,?,?,?,?,?)'
#             ins_r=db.execute_update(sql, photoList)
#             if ins_r:
#                 print('插入数据成功:')
#             else:
#                 print('插入数据失败')

    except Exception as e:
        print('错误类型： ', e)

def start_app2():
    time1 = time.time()
    filePath = 'E:/家庭照片'
    pbo = pcsbo.PcsBo()
    pbo.pcs_load(filePath)
    time2 = time.time()
    print (time2 - time1)

def start_app3():
    time1 = time.time()
    sdmd5 = 'e494ecd2759f0b8875d5e5bf752e6b0a'
    pdao = pcsdao.PcsDao()
    pd = pdao.get_pcs_directory_info('e494ecd2759f0b8875d5e5bf752e6b0a')
    print('pd size = ',pd.__len__())
    time2 = time.time()
    print (time2 - time1)   

def start_app4():
    time1 = time.time()
    pbo = pcsbo.PcsBo()
    pbo.pcs_start()
    time2 = time.time()
    print (time2 - time1)

def start_app5():
    time1 = time.time()
    filePath = 'E:/testphoto/source_photo'
    extensionTypeList ='.JPG,.jpg,.jpeg'
    fu = fileutil.FileUtil()
    str_md5 = fu.get_str_md5(filePath)
    print('str_md5=',str_md5)
#     uuid = fu.get_uuid()
    dirs_base = (fu.get_uuid(),filePath)
    dirs_dict = fu.get_directory_photo_info(filePath, extensionTypeList)
    dirs_dict['dirs_id'] = fu.get_uuid()
    dirs_dict['dirs_name'] = filePath
    dirs_dict['dirs_name_md5'] = str_md5
    print(dirs_dict)
#     dirs_info = dirs_base+dirs_nums
    num_file_extension = dirs_dict.get('num_file_extension')
    if num_file_extension > 0:
        print('符合条件开始进行扫描')
        print(dirs_dict.get('num_file_extension'))
    print(dirs_dict)
    print(dirs_dict.values())
    
    
    time2 = time.time()
    print (time2 - time1)      
 
                   
if __name__ == '__main__':
    start_app4()
#     test2()
#         testSqlite()